// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var topMenu = require("../topMenu/topMenu");
	var router = require("../hash/pageRouter");
	var leftMenu = require("../leftMenu/leftMenu");
	var footer = require("../footer/footer_main");
	var css_deliveryNoticeList = require("./deliveryNoticeList.css");
	var dialog = require("dialog");
	var databind = require("databind");
	var validate = require("validate");
	var constant = require("constant");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var left;
	var inventoryId;
	var noticeState;
	var init = function() {
		footer.init();
		$("#footer").removeClass("none");
		leftMenu.init(5);
		topMenu.init(1);
		$(".footer").removeClass("none");
		$(".table-section").removeClass("none");
		$("#leftMenu6").find(".leftMenu-item").removeClass("leftMenu-active");
		$("#leftMenu6 .leftMenu li:first-child").addClass("leftMenu-open");
		$(".deliveryNoticeList").addClass("leftMenu-active");
		inquireDeliveryNoticePageList();
		initEvent();
		router.init();

	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		//放款单查询
		$(".loanNoticeList").unbind("click").click(function() {
			location.href = "../financing/loanNoticeList.html";
		});
		//放货查询
		$(".deliveryNoticeList").unbind("click").click(function() {
			location.href = "../financing/deliveryNoticeList.html";
		});
		//收款单查询
		$(".receivableNoticeList").unbind("click").click(function() {
			location.href = "../financing/receivableNoticeList.html";
		});
		//已完成融资
		$(".endFinanceList").unbind("click").click(function() {
			location.href = "../financing/endFinanceList.html";
		});
		//收货通知查询
		$(".recieveNoticeList").unbind("click").click(function(){
		location.href="../financing/recieveNoticeList.html";
		});
		//左侧菜单栏	解除监管
		$(".cancelSuperviseA").unbind("click").click(function() {
			router.route("main/supervisionRelieveList.html?left=9", true);
		});

		//左侧菜单栏	待审批
		$(".financeUnexamA").unbind("click").click(function() {
			router.route("main/main_finance.html?left=0&financeState=1", true);
		});

		//左侧菜单栏	合同上传
		$(".contractUnsignA").unbind("click").click(function() {
			router.route("main/main_finance.html?left=1&financeState=3", true);
		});

		//左侧菜单栏	收货通知
		$(".noticeReceiveA").unbind("click").click(function() {
			router.route("main/main_finance.html?left=2&financeState=5", true);
		});

		//左侧菜单栏 放款确认
		$(".financeUnreleaseA").unbind("click").click(function() {
			router.route("main/loanNotice_list.html?left=4", true);
		});

		//左侧菜单栏  放货通知
		$(".financeUnreceiveBulkstockA").unbind("click").click(function() {
			router.route("main/deliveryNotice_list.html?left=8", true);
		});

		//左侧菜单栏 收款确认
		$(".financeUnreceiveA").unbind("click").click(function() {
			router.route("main/receivablesNotice_list.html?left=7", true);
		});

		//左侧菜单栏 通知运输
		$(".financeUntransportA").unbind("click").click(function() {
			router.route("main/transportNotice_list.html?left=5", true);
		});


		//左侧菜单栏 提货审批
		$(".financePickupExamA").unbind("click").click(function() {
			router.route("main/pickupList.html?left=6", true);
		});

		//左侧菜单栏 监管确认
		$(".financeUnsuperviseA").unbind("click").click(function() {
			router.route("main/supervisionNotice_list.html?left=3", true);
		});

		$("#receivableNoticeSearch").on("click", function() {
			pageIndex = 1;
			pageSize = 10;
			totalPageCount = 1;
			totalRecordCount = 0; //分页初始化		
			inquireDeliveryNoticePageList();
		});
	};

	//查询货箱列表
	var inquireDeliveryNoticePageList = function() {
		var logisticsCompanyName = $("#logisticsCompanyName").val();
		var financeNumber = $("#financeNumber").val();
		var productType=$(".wrapper select[name=productType]").val();
		var noticeState = $(".noticeState").val();
		base.fnAjax({
			action: "inquireDeliveryNoticePageList.json",
			oData: {
				pageIndex: pageIndex,
				pageSize: pageSize,
				noticeState: noticeState,
				logisticsCompanyName: logisticsCompanyName,
				financeNumber: financeNumber,
				enterpriseName: $("#enterpriseName").val(),
				bulkstockName: $("#bulkstockName").val(),
				productType: productType
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					var tpl = $("#bulkstockInventoryTpl").html();
					var html = juicer(tpl, data);
					$(".bulkstockInventoryTBody").html(html);
					totalPageCount = data.totalPageCount;
					totalRecordCount = data.totalRecordCount;
					base.pageControl(
						$("#pagenation"),
						totalRecordCount,
						data.pageIndex,
						data.pageSize,
						function(p) {
							pageIndex = p;
							inquireDeliveryNoticePageList();
						});
					$(".detail").unbind("click").click(function() {
						router.route("main/deliveryNotice.html?pickupId=" + $(this).parents("tr").attr("pickupId")+"&deliveryNoticeId="+$(this).parents("tr").attr("deliveryNoticeId"));
					});
				} else {
					base.alert(3, "信息获取失败");
				}
			}
		});
	}

	return {
		init: init
	};
});